clc
clear
close all;

load('pic\07-02_09.mat');
x = x(88,:);
x(end) = 0;
constX = [50e6,8];
efficiencyRoundTrip_cost = functionBPTES_exergy(x, constX);
fprintf('Round Trip Efficiency: %.4f\n', efficiencyRoundTrip_cost(1));
fprintf('Total Cost: %.2f M EUR\n', efficiencyRoundTrip_cost(2)/1e6);

powerNominalCharge = constX(1);
chargingHours = constX(2);
UA_Reg = x(1);
UA_Hot = x(2);
UA_Cold = x(3);
T1Charge = x(4);
T4Charge = x(5);
T1Discharge = x(6);
T4Discharge = x(7);
pressureRatio = x(8);
capacityMassGain = x(9);

BPTESobj = BPTES(powerNominalCharge, chargingHours, UA_Reg, UA_Hot, UA_Cold, T1Charge, T4Charge, T1Discharge, T4Discharge, pressureRatio, capacityMassGain);

investCostTotal = BPTESobj.investCostTotal;
investCostTurbine = BPTESobj.investCostTurbine;
investCostCompressor = BPTESobj.investCostCompressor;
investCostHeatExchanger = BPTESobj.investCostHeatExchanger;
investCostMotor = BPTESobj.investCostMotor;
investCostgenerator = BPTESobj.investCostgenerator;
investCostTank = BPTESobj.investCostTank;
investCostMaterial = BPTESobj.investCostMaterial;


components = {'Turbine', 'Generator+Gearbox', 'Compressor', 'Motor+Gearbox', 'Tank+Material', 'HeatExchanger'};
costs = [investCostTurbine, ...
          investCostgenerator, ...
          investCostCompressor, ...
          investCostMotor, ...
          investCostTank + investCostMaterial, ...
          investCostHeatExchanger];

% Create the bar chart
figure;
bar(costs);
set(gca, 'XTick', 1:length(components), 'XTickLabel', components);
% xtickangle(45); % Rotate the labels for better readability
ylabel('Investment Cost ($)');
title('BPTES System Component Investment Costs');
grid on;


% Add cost values on top of bars
for i = 1:length(costs)
    text(i, costs(i) + max(costs)*0.02, num2str(costs(i), '%.2e'), 'HorizontalAlignment', 'center');
end



